package com.chinaunicom.emergency.repository;

import com.chinaunicom.emergency.model.Rolepermissions;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * @author liliang
 * @date 2018/1/15
 * Email : 18633533023@163.com
 * QQ : 284067520
 * 角色资源
 */
public interface RolePermissionsRepository extends JpaRepository<Rolepermissions,String>, JpaSpecificationExecutor {

    @Query(nativeQuery = true,value = "select distinct per.PERMISSIONS_CODE,rp.PERMISSIONS_ID,per.appkey from YJGL_ROLEPERMISSIONS rp,YJGL_PERMISSIONS per where rp.PERMISSIONS_ID = per.PID and rp.ROLE_ID in (?1) and per.IS_SOFT_DEL = 0 ")
    List findPermissionByRoleId(List<String> roleIds);

    void deleteByRoleId(String roleId);

    @Query(nativeQuery = true,value = "select r.ROLE_NAME from YJGL_ROLEPERMISSIONS rp,YJGL_ROLE r where r.PID = rp.ROLE_ID and rp.PERMISSIONS_ID = ?1")
    List<String> findRoleNameByPermissionId(String perId);
}
